<?php
if (isset ($a_sRequest [2]))
{
	$iNewsId = $a_sRequest [2];
	$sQuery = 'SELECT `titel`, `voornaam`, `achternaam`, `inhoud`, `nieuws_id` FROM nieuws NATURAL JOIN `user` WHERE `nieuws_id` = :iNewsId';
	try
	{
		$oStmt = $pPDO -> prepare ($sQuery);
		$oStmt -> bindParam (':iNewsId', $iNewsId, PDO::PARAM_INT);
		$oStmt -> execute ();
		$oStmt -> bindColumn ('titel', $sNewsTitle);
		$oStmt -> bindColumn ('voornaam', $sFirstName);
		$oStmt -> bindColumn ('achternaam', $sName);
		$oStmt -> bindColumn ('inhoud', $sContent);
		$oStmt -> bindColumn ('nieuws_id', $iNewsId);
		$oStmt -> fetch (PDO::FETCH_BOUND);
		if (str_replace('_', ' ', urldecode ($a_sRequest [3])) == $sNewsTitle)
		{
			echo '<h2 style="margin-top:0px;margin-bottom:0px;">' . $sNewsTitle . '</h2>
			<p style="font-size:12px;">Geschreven door <i>' . $sFirstName . ' ' . $sName . '</i></p><br />';
			echo stripslashes($sContent);
			echo '<br />';
			?>
				<hr style="margin: 0; padding: 0;"; />
			<?php
			$sMode = 'nieuws';
			include ('cms/modules/_social-media/index.php');
			//echo '<hr style="margin: 0; padding: 0;";/>';
			//include ('modules/nieuws/reactions/index.php');
		}
		else
		{
			$sTitle = NULL;
		}
	}
	catch (PDOException $e)
	{
		ePDOException :: writeMessage ($e);
	}
}
else
{
	$sQuery = "SELECT `nieuws_id`, `titel`, `voornaam`, `achternaam`, `inhoud` FROM nieuws NATURAL JOIN `user` WHERE `active` = 1 ORDER BY `nieuws_id` DESC;";
	if (isset ($aArgs['limit']))
	{
		$sQuery .=  " LIMIT " . $aArgs['limit'];
	}
	
	try
	{
		$oStmt = $pPDO -> prepare ($sQuery);
		$oStmt -> execute ();
		$oStmt -> bindColumn ('nieuws_id', $iNewsId);
		$oStmt -> bindColumn ('titel', $sNewsTitle);
		$oStmt -> bindColumn ('voornaam', $sFirstName);
		$oStmt -> bindColumn ('achternaam', $sName);
		$oStmt -> bindColumn ('inhoud', $sContent);
		$iNumber = $oStmt -> rowCount ();
		$iA = 1;
		while ($result = $oStmt -> fetch (PDO::FETCH_BOUND))
// 		foreach ($result as $row)
		{
		?>
			<table cellpadding=5 cellspacing=0 border=0 style="table-layout:fixed" width="341">
			</tr>
				<td width="150"></td>
				<td width="300"><?php echo '<h2><a href="' . $a_sRequest [0] . '/' . urlencode ($sTitle) . '/' . $iNewsId . '/' . urlencode (str_replace(' ', '_', $sNewsTitle)) . '.html">' . $sNewsTitle . '</a></h2>' ?></td>
			</tr>
			<tr>
				<td width="150">Geschreven door:</td>
				<td width="300"><?php echo $sFirstName ?>&nbsp;<?php echo $sName ?></td>
			<br>
			<tr>
				<td width="150"></td>
				<td width="300"><?php echo $sContent ?></td>
			</tr>
		</table>
		<hr style="margin: 0; padding: 0;"; />
		<?php
		$sMode = 'nieuws';
		include ('cms/modules/_social-media/index.php');
		?>
			<?php
			if ($iA < $iNumber)
			{
				echo '<hr style="margin: 0; padding: 0;";/>';
			}
			
			$iA++;
		}
	}
	catch (PDOException $e)
	{
		ePDOException :: writeMessage ($e);
	}
}
?>
